<?php
/**
 *  Binds product data to HTML rendering
 */
class ProductView {
	/**
	 * Private
	 * $model an instance of the ProductModel class
	 */
	var $model;

	/**
	 * Private
	 * $output rendered HTML is stored here for display
	 */
	var $output;

	//! A constructor.
	/**
	 * Constucts a new ProductView object
	 * @param $model an instance of the ProductModel class
	 */
	function ProductView (&$model) {
		$this->model=& $model;
	}

	//! A manipulator
	/**
	 * Builds the top of an HTML page
	 * @return void
	 */
	function header () {
		echo "Header<br/>";		
	}

	//! A manipulator
	/**
	 * Builds the bottom of an HTML page
	 * @return void
	 */
	function footer () {
		echo "Footer";
	}

	//! A manipulator
	/**
	 * Displays a single product
	 * @return void
	 */
	function productItem($id=1) {
		$this->model->listProduct($id);
		while ( $product=$this->model->getProduct() ) {
			// Bind data to HTML
			$this->output .= "$id-->". $product["id"];
		}
	}

	//! A manipulator
	/**
	 * Builds a product table
	 * @return void
	 */
	function productTable($rownum=1) {
		$rowsperpage='20';
		$this->model->listProducts($rownum,$rowsperpage);
		while ( $product=$this->model->getProduct() ) {			
			// Bind data to HTML
			$this->output .= "$rownum-->". $product["id"];
		}
	}

	//! An accessor
	/**
	 * Returns the rendered HTML
	 * @return string
	 */
	function display () {
		return $this->output;
	}
}
?>